package com.wanmait.recruitment.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.pojo.Friendly;
import com.wanmait.recruitment.service.ConfigService;
import com.wanmait.recruitment.service.FriendlyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("manage/friendly")
public class FriendlyListController {
    @Resource
    private FriendlyService friendlyService;
    @Resource
    private ConfigService configService;
    @RequestMapping("list")
    public void list(){

    }
    @RequestMapping("date")
    public ModelAndView date(Friendly friendly, int pageNumber){
        ModelAndView modelAndView = new ModelAndView();
        int pageNum;
        try {
            pageNum = pageNumber;
        } catch (Exception e) {
            pageNum = 1;
        }
        int pageSize;
        try {
            pageSize = Integer.parseInt(configService.getValueByKey("frienfly_config"));
        } catch (NumberFormatException e) {
            pageSize = Integer.parseInt(configService.getDefaultValueByKey("frienfly_config"));
        }
        PageInfo<Friendly> friendlyPageInfo = friendlyService.findList(friendly,pageNum,pageSize);
        modelAndView.addObject("friendlyPageInfo",friendlyPageInfo);
        return modelAndView;
    }
    @RequestMapping("del")
    @ResponseBody
    public void del(String id){
        friendlyService.delete(Integer.parseInt(id));
    }
    @RequestMapping("batchDel")
    @ResponseBody
    public void batchDel(String ids){
        friendlyService.delete(ids);
    }
    @RequestMapping("update")
    @ResponseBody
    public void update(Friendly friendly){
        friendlyService.update(friendly);
    }
    @RequestMapping("insert")
    @ResponseBody
    public void insert(Friendly friendly){
        friendlyService.insert(friendly);
    }
}
